import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  OneToOne,
  JoinColumn,
  OneToMany,
  ManyToOne,
} from 'typeorm';
import { User } from './user.entity';
import { ApiProperty } from '@nestjs/swagger';

@Entity('user_info')
export class UserInfo {
  // 创建一个字段并设置为主键
  @ApiProperty({ description: 'id' })
  @PrimaryGeneratedColumn()
  id: number;

  @ApiProperty({ description: '昵称' })
  @Column()
  real_name: string;

  @ApiProperty({ description: '性别' })
  @Column()
  gender: string;

  @ApiProperty({ description: '手机号' })
  @Column()
  phone: string;

  @ApiProperty({ description: '头像' })
  @Column()
  avatar: string;

  @ApiProperty({ description: '出生年月' })
  @Column({ type: 'date', nullable: true })
  birth: string;

  @ApiProperty()
  @Column({
    name: 'create_time',
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP',
  })
  createTime: Date;

  @ApiProperty()
  @Column({
    name: 'update_time',
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP',
  })
  updateTime: Date;

  // 用户会员等级 0 普通用户 1青铜 2白银 3黄金 4钻石
  @ApiProperty({ description: '会员等级' })
  @Column({
    type: 'enum',
    enum: [0, 1, 2, 3, 4],
    default: 0,
  })
  vip: number;

  @OneToOne(() => User, (user) => user.userInfo)
  @JoinColumn({ name: 'userId' })
  user: User;

  @Column({ type: 'int', unique: true })
  userId: number;
}
